package com.weasing.res.web.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.weasing.res.dao.IWxEvalresultDao;
import com.weasing.res.dao.IWxUserdetailDao;
import com.weasing.res.service.IWxUserdetailService;
import com.weasing.res.service.IWxUserlistService;
import com.weasing.res.utils.JsonUtils;
import com.weasing.res.utils.RESUtils;
import com.weasing.res.vo.EchartsVO;
import com.weasing.res.web.action.base.BaseAction;

/**
 * 
 * 图形统计的方法
 * 
 * 还能优化 只需要写一个方法
 * 
 * TODO 没时间 暂时写死
 * 
 * @author long
 *
 */
@Controller
@Scope("prototype")
public class StatAction extends BaseAction<Object> {

	@Autowired
	private IWxUserdetailService wxUserdetailService;
	@Autowired
	private IWxUserlistService wxUserlistService;
	@Autowired // 没办法 这个service不能继承我的base接口 ...
	private IWxUserdetailDao wxUserdetaildao;
	@Autowired
	private IWxEvalresultDao wxEvalresultDao;

	Map<String, Object> map = new HashMap<String, Object>();

	/**
	 * 
	 * 引入界面方法
	 * 
	 * @author 黄龙
	 * 
	 */
	public String list() {
		return "list";
	}
	/**
	 * 嫌疑人表
	 * 
	 * 统计的方法 前[0][1]是 批捕情况统计
	 * 
	 * @author 黄龙
	 */
	public void userSexCount() {
		// 查询性别为女的嫌疑犯的个数
		map.clear();
		map.put("sex", (short) 1);
		Integer FemaleCount = wxUserlistService.findCountByField(map);
		EchartsVO voFemaleCount = new EchartsVO();
		voFemaleCount.setName("女");
		voFemaleCount.setValue(FemaleCount);
		// 查询性别为男的嫌疑犯的个数
		map.clear();
		map.put("sex", (short) 2);
		Integer MaleCount = wxUserlistService.findCountByField(map);
		EchartsVO voMaleCount = new EchartsVO();
		voMaleCount.setName("男");
		voMaleCount.setValue(MaleCount);

		String beanstoJsonArray = JsonUtils.BeanstoJsonArray(voMaleCount,
				voFemaleCount);
		RESUtils.printJSON(beanstoJsonArray);
	}

	/**
	 * 评估表
	 * 
	 * 初犯 累犯 统计
	 * 
	 * @author 黄龙
	 * 
	 */
	public void crimeTypeCount() {
		// 表wx_userdetail 字段crimetype 1.其他 2.初犯 3.偶犯 4. 累犯
		map.clear();
		map.put("crimetype", 1);
		Integer count1 = wxUserdetaildao.findCountByField(map);
		EchartsVO vo1 = new EchartsVO();
		vo1.setName("其他");
		vo1.setValue(count1);

		map.clear();
		map.put("crimetype", 2);
		Integer count2 = wxUserdetaildao.findCountByField(map);
		EchartsVO vo2 = new EchartsVO();
		vo2.setName("初犯");
		vo2.setValue(count2);

		map.clear();
		map.put("crimetype", 3);
		Integer count3 = wxUserdetaildao.findCountByField(map);
		EchartsVO vo3 = new EchartsVO();
		vo3.setName("偶犯");
		vo3.setValue(count3);

		map.clear();
		map.put("crimetype", 4);
		Integer count4 = wxUserdetaildao.findCountByField(map);
		EchartsVO vo4 = new EchartsVO();
		vo4.setName("累犯");
		vo4.setValue(count4);


		String beanstoJsonArray = JsonUtils.BeanstoJsonArray(vo1,
				vo2, vo3, vo4);
		RESUtils.printJSON(beanstoJsonArray);
	}

	/**
	 * 评估表
	 * 
	 * 案件类型统计
	 * 
	 * @author 黄龙
	 * 
	 */
	public void chargetypeCount() {
		// 表wx_userdetail 字段chargetype 1.抢夺罪 2.故意伤害罪 3.盗窃罪 4. 交通肇事罪 5.其他
		map.clear();
		map.put("chargetype", 1);
		Integer count1 = wxUserdetaildao.findCountByField(map);
		EchartsVO vo1 = new EchartsVO();
		vo1.setName("抢夺罪");
		vo1.setValue(count1);

		map.clear();
		map.put("chargetype", 2);
		Integer count2 = wxUserdetaildao.findCountByField(map);
		EchartsVO vo2 = new EchartsVO();
		vo2.setName("故意伤害罪");
		vo2.setValue(count2);

		map.clear();
		map.put("chargetype", 3);
		Integer count3 = wxUserdetaildao.findCountByField(map);
		EchartsVO vo3 = new EchartsVO();
		vo3.setName("盗窃罪");
		vo3.setValue(count3);

		map.clear();
		map.put("chargetype", 4);
		Integer count4 = wxUserdetaildao.findCountByField(map);
		EchartsVO vo4 = new EchartsVO();
		vo4.setName("交通肇事罪");
		vo4.setValue(count4);

		map.clear();
		map.put("chargetype", 5);
		Integer count5 = wxUserdetaildao.findCountByField(map);
		EchartsVO vo5 = new EchartsVO();
		vo5.setName("其他");
		vo5.setValue(count5);

		String beanstoJsonArray = JsonUtils.BeanstoJsonArray(vo1,
				vo2, vo3, vo4, vo5);
		RESUtils.printJSON(beanstoJsonArray);
	}

	/**
	 * 评估统计
	 * 
	 * 羁押情况
	 * 
	 * @author 黄龙
	 * 
	 */

	public void jiyaCount() {

		Integer jiyaCount = wxEvalresultDao.jiyaCount();
		Integer nojiyaCount = wxEvalresultDao.nojiyaCount();

		EchartsVO vo1 = new EchartsVO();
		vo1.setName("已批准羁押");
		vo1.setValue(jiyaCount);

		EchartsVO vo2 = new EchartsVO();
		vo2.setName("未批准羁押");
		vo2.setValue(nojiyaCount);

		String beanstoJsonArray = JsonUtils.BeanstoJsonArray(vo1,
				vo2);
		RESUtils.printJSON(beanstoJsonArray);
	}

	/**
	 * 获得嫌疑人的年龄统计
	 * 
	 */
	public void ageCount() {
		Integer ageCount1 = wxUserlistService.ageCount(0, 20);
		Integer ageCount2 = wxUserlistService.ageCount(21, 30);
		Integer ageCount3 = wxUserlistService.ageCount(31, 40);
		Integer ageCount4 = wxUserlistService.ageCount(41, 50);
		Integer ageCount5 = wxUserlistService.ageCount(51, 200);
		Integer ageCount6 = wxUserlistService.findCount() - ageCount1
				- ageCount2 - ageCount3 - ageCount4 - ageCount1;


	}
}
